{
    require('./style.css')
    const NAME = 'components.server'
    module.exports = require('angular')
        .module(NAME, [
            require(__SERVICES__ + '/efunfun/server').name,
            require(__COMPONENTS__ + '/server/service').name
        ])
        .directive(NAME, function (server, serverservice) {
            return {
                scope: {},
                replace: true,
                template: require('./template.html'),
                link: function (scope, ele, attr) {
                    scope.serverListScrollFlag = false
                    scope.showMoreServers = false
                    server.getServerList().success(function (data, status, headers, config) { // 渲染服务器列表
                        scope.serverListScrollFlag = true
                        scope.recommendServers = []
                        scope.allServers = []
                        var len = data.length - 1
                        for (var i = len; i >= 0; i--) {
                            var object = data[i]
                            if (object.STATE * 1 === 1) {
                                scope.recommendServers.push(object)
                            }
                            scope.allServers.push(object)
                        }
                        serverservice.serverList = scope.allServers
                    })
                },
                controller: NAME
            }
        })
        .controller(NAME, function ($scope, $timeout, serverservice) {
            $scope.checkMoreServers = function () {
                $scope.showMoreServers = true
                serverservice.showMoreServers = true
                if ($scope.serverListScrollFlag) {
                    $scope.serverListScrollFlag = false
                    $timeout(function () {
                        $scope.createScrollBar()
                    })
                }
            }
            $scope.shutOff = function () {
                $scope.showMoreServers = false;
                serverservice.showMoreServers = false
            }
            $scope.createScrollBar = function () {
                $scope.scrollMe = require(__LIBS__ + '/scroll/scroll.ts')({
                    contain: 'scrollList',
                    wrap: 'scrollListWrap',
                    scrollBg: 'scrollBg',
                    scrollBlock: 'scrollBlock',
                    heightFix: document.getElementById('scrollListWrap').offsetHeight
                })
                $scope.scrollMe.init(document.documentElement.clientWidth, document.documentElement.clientHeight);
            }
        })
}
